<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <title>Angular-basic</title>
</head>
<body ng-app="app">

<div class="container">
    <h2 class="text-primary">

    </h2>
    姓名:<input id="user_name" type="text"><br>
    发送给：<input type="text" id="to"><br>
    消息内容:<input type="text" id="message"><button type="button" id="send">发送</button>
    <ul id="message_list">

    </ul>
</div>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/socket.io/socket.io-client/socket.io.js"></script>
<script>
    $(function(){
        var socket = io.connect('http://localhost:3000');
        socket.on('connect', function (data) {
            console.log(data);
        });
        $("#send").click(function(e){
            var from = $('#user_name').val(),
                    msg  = $('#message').val(),
                    to   = $('#to').val(),
                    $message_list = $('#message_list');
            socket.emit('new user',from);
            socket.emit('private message',from,to,msg);
            socket.on('to'+from, function (data) {
                $message_list.append('<li>'+data.from+'说'+data.message+'</li><li>');
            });
        });
    });

</script>
</body>
</html>
